import React, { useEffect, useState } from 'react'
import { useSelector,useDispatch } from 'react-redux'
import { changeName,changeAge } from '../store/models/user'
import { changeInfo } from '../store/models/goods'
const Child1 = () => {
    const dispatch = useDispatch()
    const username = useSelector(state => {
        console.log('数据',state)
        return state.user.name
    })
    console.log(username)
    const age = useSelector(state => {
        return state.user.age
    })
    const info = useSelector(state => {
        return state.goods
    })
  return (
    <div>
        <h1>Child1</h1>
        {/* <button onClick={() => {
            dispatch(changeInfo({
                title:'苹果',
                price:22,
                count:10
            }))
        }}>修改商品</button>
        <p>商品:{JSON.stringify(info)}</p>
        <p>姓名:{username}</p>
        <p>年龄:{age}</p> */}
        <button onClick={() => {
            dispatch(changeName(Math.random()))
        }}>修改姓名</button>
        <button onClick={() => {
            console.log(changeAge(3))
            dispatch(changeAge(3))
        }}>age+3</button>
        <button onClick={() => {
            dispatch(changeAge(-2))
        }}>age-2</button>
    </div>
  )
}

export default Child1